#define TRIG 9
#define ECHO 10

int pot1 = A0;
int pot2 = A1;
int pot3 = A2;
int pot4 = A3;

int button1 = 2;
int button2 = 3;

long readDistance() {
  digitalWrite(TRIG, LOW);
  delayMicroseconds(5);

  digitalWrite(TRIG, HIGH);
  delayMicroseconds(15);
  digitalWrite(TRIG, LOW);

  long duration = pulseIn(ECHO, HIGH, 30000);

  if(duration == 0) return -1;
  return duration * 0.034 / 2;
}

void setup() {
  Serial.begin(115200);

  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);

  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
}

void loop() {

  long dist = readDistance();

  int p1 = analogRead(pot1);
  int p2 = analogRead(pot2);
  int p3 = analogRead(pot3);
  int p4 = analogRead(pot4);

  int b1 = digitalRead(button1);
  int b2 = digitalRead(button2);

  Serial.print(dist); Serial.print(",");
  Serial.print(p1); Serial.print(",");
  Serial.print(p2); Serial.print(",");
  Serial.print(p3); Serial.print(",");
  Serial.print(p4); Serial.print(",");
  Serial.print(b1); Serial.print(",");
  Serial.println(b2);

  delay(30);
}
